from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from public.config import config


url: str = "postgresql+psycopg2://{}:{}@{}:{}/{}"
# url: str = "mysql+pymysql://{0}:{1}@{2}:{3}/{4}"
url: str = url.format(config.PG_USER, config.PG_PASSWORD, config.PG_HOST, config.PG_PORT, config.PG_DB_NAME)

# url="postgresql+psycopg2://postgres:123456789@127.0.0.1:5432/data",

engine = create_engine(
    url=url,
    max_overflow=32,
    pool_size=8,
    pool_timeout=32,
    pool_recycle=3600,
    # echo=True if config.develop else False,
    echo=False,
    echo_pool=False
)

SessionFactory = sessionmaker(bind=engine)
BaseModels = declarative_base()


def initialize() -> None:

    # 生产过程中数据采集（物料、产品码、）
    from . import course

    # 设备管理模块(设备添加、设备报警、设备维修记录、设备保养日记)
    from . import facility

    # 额外的、首件、 报表负责人
    from . import extra

    # 日志
    from . import logs

    # 订单、任务模块
    from . import order

    # 订单、任务模块
    from . import order

    # 班次
    from . import owner

    # 产品、
    from . import product

    # 用户管理模块
    from . import users


initialize()
